package com.example.springsecuritydemo.controller;

import org.springframework.security.access.annotation.Secured;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Classname: LoginController
 * @Description: 登录controller
 * @Date: 2021/3/15 20:19
 * @Created: by Wang Xu
 */
@Controller
public class LoginController {

//    @RequestMapping("/login")
//    public String login() {
//        System.out.println("执行登录方法");
//        return "redirect:main.html";
//    }

//    @Secured("ROLE_abc")
    // PreAuthorize 的表达式允许ROLE_开头，也可以不以ROLE_开头。 配置类不可以 也是严格区分大小写
    @PreAuthorize("hasRole('ROLE_abc')")
    @PostMapping("/toMain")
    public String toMain() {
        return "redirect:main.html";
    }

    @PostMapping("/toError")
    public String toError() {
        return "redirect:error.html";
    }

    @GetMapping("/demo1")
    @ResponseBody
    public String demo1() {
        return "demo";
    }

    @RequestMapping("/demo")
    public String demo() {
        return "demo";
    }

    @RequestMapping("toLogin")
    public String toLogin() {
        return "login";
    }

}
